package com.toivan.mt.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.hwangjr.rxbus.RxBus;
import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.annotation.Tag;
import com.hwangjr.rxbus.thread.EventThread;
import com.toivan.mt.R;
import com.toivan.mt.model.MtEffectFilterEnum;
import com.toivan.mt.model.MtQuickBeautyDefault;
import com.toivan.mt.model.MtSharedPrefKey;
import com.toivan.mt.model.MtToneFilterEnum;
import com.toivan.mt.model.RxBusAction;
import com.toivan.mt.utils.MtSharedPreferences;
import com.toivan.sdk.MtSDK;

public class MtBarView extends LinearLayout {
    private MtSDK mtSDK;

    private TextView bubbleTV;
    private TextView numberTV;
    private SeekBar seekBar;
    private View progressV;
    private View middleV;
    private ImageView renderEnableIV;

    public String currentAction = RxBusAction.ACTION_WHITENESS;
    private String currentBeautyAction = RxBusAction.ACTION_WHITENESS;
    private String currentFaceTrimAction = RxBusAction.ACTION_EYE_ENLARGING;
    //    private String currentQuickBeautyAction = MtSharedPrefKey.currentQuickBeautyAction;
    private MtQuickBeautyDefault quickBeautyDefault = MtSharedPrefKey.quickBeautyDefault;

    private String filterName = MtSharedPrefKey.filterName;
    private MtEffectFilterEnum effectFilterEnum = MtSharedPrefKey.effectFilterEnum;
    private MtToneFilterEnum toneFilterEnum = MtSharedPrefKey.toneFilterEnum;


    private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!fromUser) {
                Log.e("myLog", "not from user");
                return;
            }

            switch (currentAction) {
                //美颜
                case RxBusAction.ACTION_WHITENESS:
                    styleNormal(progress);
                    mtSDK.setWhitenessValue(progress);
                    MtSharedPreferences.getInstance().setWhitenessValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_BLURRINESS:
                    styleNormal(progress);
                    mtSDK.setBlurrinessValue(progress);
                    MtSharedPreferences.getInstance().setPreciseSkin(0);
                    MtSharedPreferences.getInstance().setBlurrinessValue(progress);
                    postEnableReset();
                    break;
                //精准美肤
                case RxBusAction.ACTION_PRECISE_SKIN:
                    styleNormal(progress);
                    mtSDK.setPrecisenessValue(progress);
                    MtSharedPreferences.getInstance().setBlurrinessValue(0);
                    MtSharedPreferences.getInstance().setPreciseSkin(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_ROSINESS:
                    styleNormal(progress);
                    mtSDK.setRosinessValue(progress);
                    MtSharedPreferences.getInstance().setRosinessValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_CLEARNESS:
                    styleNormal(progress);
                    mtSDK.setClearnessValue(progress);
                    MtSharedPreferences.getInstance().setClearnessValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_BRIGHTNESS:
                    styleTransform(progress);
                    mtSDK.setBrightnessValue(progress - 50);
                    MtSharedPreferences.getInstance().setBrightnessValue(progress - 50);
                    postEnableReset();
                    break;

                //美型
                case RxBusAction.ACTION_EYE_ENLARGING:
                    styleNormal(progress);
                    mtSDK.setEyeEnlargingValue(progress);
                    MtSharedPreferences.getInstance().setEyeEnlargingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_CHEEK_THINNING://瘦脸
                    styleNormal(progress);
                    mtSDK.setCheekThinningValue(progress);
                    MtSharedPreferences.getInstance().setCheekThinningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_CHEEK_NARROWING://窄脸
                    styleNormal(progress);
                    mtSDK.setCheekNarrowingValue(progress);
                    MtSharedPreferences.getInstance().setCheekNarrowingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_CHEEK_BONE_THINNING:
                    styleNormal(progress);
                    mtSDK.setCheekboneThinningValue(progress);
                    MtSharedPreferences.getInstance().setCheekboneThinningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_JAW_BONE_THINNING:
                    styleNormal(progress);
                    mtSDK.setJawboneThinningValue(progress);
                    MtSharedPreferences.getInstance().setJawboneThinningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_TEMPLE_ENLARGING:
                    styleNormal(progress);
                    mtSDK.setTempleEnlargingValue(progress);
                    MtSharedPreferences.getInstance().setTempleEnlargingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_HEAD_LESSENING:
                    styleNormal(progress);
                    mtSDK.setHeadLesseningValue(progress);
                    MtSharedPreferences.getInstance().setHeadLesseningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_FACE_LESSENING:
                    styleNormal(progress);
                    mtSDK.setFaceLesseningValue(progress);
                    MtSharedPreferences.getInstance().setFaceLesseningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_CHIN_TRIMMING:
                    styleTransform(progress);
                    mtSDK.setChinTrimmingValue(progress - 50);
                    MtSharedPreferences.getInstance().setChinTrimmingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_PHILTRUM_TRIMMING:
                    styleTransform(progress);
                    mtSDK.setPhiltrumTrimmingValue(-(progress - 50));
                    MtSharedPreferences.getInstance().setPhiltrumTrimmingValue(-(progress - 50));
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_FOREHEAD_TRIMMING:
                    styleTransform(progress);
                    mtSDK.setForeheadTrimmingValue(progress - 50);
                    MtSharedPreferences.getInstance().setForeheadTrimmingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_EYE_SPACING:
                    styleTransform(progress);
                    mtSDK.setEyeSpacingTrimmingValue(progress - 50);
                    MtSharedPreferences.getInstance().setEyeSpacingTrimmingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_EYE_CORNER_TRIMMING:
                    styleTransform(progress);
                    mtSDK.setEyeCornerTrimmingValue(progress - 50);
                    MtSharedPreferences.getInstance().setEyeCornerTrimmingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_EYE_CORNER_ENLARGING:
                    styleNormal(progress);
                    mtSDK.setEyeCornerEnlargingValue(progress);
                    MtSharedPreferences.getInstance().setEyeCornerEnlargingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_NOSE_ENLARGING:
                    styleTransform(progress);
                    mtSDK.setNoseEnlargingValue(progress - 50);
                    MtSharedPreferences.getInstance().setNoseEnlargingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_NOSE_THINNING:
                    styleTransform(progress);
                    mtSDK.setNoseThinningValue(-(progress - 50));
                    MtSharedPreferences.getInstance().setNoseThinningValue(-(progress - 50));
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_NOSE_APEX_LESSENING:
                    styleNormal(progress);
                    mtSDK.setNoseApexLesseningValue(progress);
                    MtSharedPreferences.getInstance().setNoseApexLesseningValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_NOSE_ROOT_ENLARGING:
                    styleNormal(progress);
                    mtSDK.setNoseRootEnlargingValue(progress);
                    MtSharedPreferences.getInstance().setNoseRootEnlargingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_MOUTH_TRIMMING:
                    styleTransform(progress);
                    mtSDK.setMouthTrimmingValue(progress - 50);
                    MtSharedPreferences.getInstance().setMouthTrimmingValue(progress - 50);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_MOUTH_SMILING:
                    styleNormal(progress);
                    mtSDK.setMouthSmilingEnlargingValue(progress);
                    MtSharedPreferences.getInstance().setMouthSmilingEnlargingValue(progress);
                    postEnableReset();
                    break;

                case RxBusAction.ACTION_DARK_CIRCLES:
                    //去黑眼圈
                    styleNormal(progress);
                    Log.i("设置黑眼圈:", progress + "%");
                    mtSDK.setDarkCircleRemovingValue(progress);
                    MtSharedPreferences.getInstance().setDarkCircleValue(progress);
                    postEnableReset();
                    break;

                //滤镜
                case RxBusAction.ACTION_FILTER:
                    styleNormal(progress);
                    mtSDK.setBeautyFilterName(filterName, progress);
                    MtSharedPreferences.getInstance().setBeautyFilterValue(filterName, progress);
                    break;

                //特效滤镜
                case RxBusAction.ACTION_EFFECT_FILTER:
                    styleNormal(progress);
                    mtSDK.setEffectFilterType(effectFilterEnum.getEffectFilter(), progress);
                    MtSharedPreferences.getInstance().setEffectFilterValue(effectFilterEnum.getFilterName(getContext()), progress);
                    break;

                //调色滤镜
                case RxBusAction.ACTION_TONE_FILTER:
                    styleNormal(progress);
                    mtSDK.setToneFilterType(toneFilterEnum.getToneFilter(), progress);
                    MtSharedPreferences.getInstance().setToneFilterValue(toneFilterEnum.getFilterName(getContext()), progress);
                    break;

                //一键美颜
                case RxBusAction.ACTION_QUICK_BEAUTY:
                    styleNormal(progress);
                    mtSDK.setBeautyStyle(quickBeautyDefault.beautyStyle, progress);
                    setQuickBeauty(quickBeautyDefault, progress);
                    MtSharedPreferences.getInstance().setQuickBeautyValue(quickBeautyDefault.name(), progress);
                    break;

            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            bubbleTV.setVisibility(VISIBLE);
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            bubbleTV.setVisibility(GONE);
        }
    };

    public MtBarView(Context context) {
        super(context);
    }

    public MtBarView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MtBarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public MtBarView init(MtSDK mtSDK) {
        this.mtSDK = mtSDK;

        RxBus.get().register(this);

        initView();

        initData();

        return this;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        RxBus.get().unregister(this);
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_mt_bar, this);

        bubbleTV = findViewById(R.id.bubbleTV);
        numberTV = findViewById(R.id.numberTV);
        seekBar = findViewById(R.id.seekBar);
        progressV = findViewById(R.id.progressV);
        middleV = findViewById(R.id.middleV);
        renderEnableIV = findViewById(R.id.renderEnableIV);
    }

    @SuppressLint("ClickableViewAccessibility")
    private void initData() {

        seekBar.setOnSeekBarChangeListener(onSeekBarChangeListener);
        seekBar.setProgress(0);

        renderEnableIV.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mtSDK.setRenderEnable(false);
                        return true;
                    case MotionEvent.ACTION_UP:
                        mtSDK.setRenderEnable(true);
                        return true;
                }
                return false;
            }
        });
    }

    private void styleNormal(int progress) {

        seekBar.setSecondaryProgress(0);
        middleV.setVisibility(GONE);

        CharSequence percent = new StringBuilder().append(progress).append("%");

        numberTV.setText(percent);

        float width = seekBar.getWidth() - (getContext().getResources().getDisplayMetrics().density * 32 + 0.5f);

        bubbleTV.setText(percent);
        bubbleTV.setX(width / 100 * progress + (getContext().getResources().getDisplayMetrics().density * 1f + 0.5f));

        progressV.setVisibility(GONE);
    }

    private void styleTransform(int progress) {

        seekBar.setSecondaryProgress(50);
        middleV.setVisibility((progress > 48 && progress < 52) ? GONE : VISIBLE);

        CharSequence percent = new StringBuilder().append(progress - 50).append("%");

        numberTV.setText(percent);

        float width = seekBar.getWidth() - (getContext().getResources().getDisplayMetrics().density * 32 + 0.5f);

        bubbleTV.setText(percent);
        bubbleTV.setX(width / 100 * progress + (getContext().getResources().getDisplayMetrics().density * 1f + 0.5f));

        progressV.setVisibility(VISIBLE);
        float dp5 = getContext().getResources().getDisplayMetrics().density * 5f + 0.5f;
        ViewGroup.LayoutParams layoutParams = progressV.getLayoutParams();
        if(width / 100 * progress > dp5) {
            layoutParams.width = (int) (progress < 53 ? width / 100 * progress - dp5 : width / 2);
        } else {
            layoutParams.width = 0;
        }
        progressV.setLayoutParams(layoutParams);
    }

    public void selectBeauty() {
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);

        seekBar.setEnabled(MtSharedPreferences.getInstance().isFaceBeautyEnable());

        busCurrentAction(currentBeautyAction);
    }

    public void selectFaceTrim() {
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        seekBar.setEnabled(MtSharedPreferences.getInstance().isFaceShapeEnable());
        busCurrentAction(currentFaceTrimAction);
    }

    public void selectFilter() {
        currentAction = RxBusAction.ACTION_FILTER;
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        seekBar.setEnabled(true);
    }

    public void selectEffectFilter() {
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        seekBar.setEnabled(true);
        busCurrentEffectFilter(effectFilterEnum);
    }

    public void selectToneFilter() {
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        seekBar.setEnabled(true);
        busCurrentToneFilter(toneFilterEnum);
    }

    public void selectQuickBeauty() {
        currentAction = RxBusAction.ACTION_QUICK_BEAUTY;
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        seekBar.setEnabled(true);
    }

    public void hideSeekBar() {
        numberTV.setVisibility(INVISIBLE);
        seekBar.setVisibility(INVISIBLE);
        progressV.setVisibility(GONE);
        middleV.setVisibility(GONE);
    }

    public void showNormalSeekBar() {
        numberTV.setVisibility(VISIBLE);
        seekBar.setVisibility(VISIBLE);
        progressV.setVisibility(GONE);
        middleV.setVisibility(GONE);
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = @Tag(RxBusAction.ACTION_FILTER))
    public void busCurrentFilter(String filterName) {

        currentAction = RxBusAction.ACTION_FILTER;
        this.filterName = filterName;
        MtSharedPrefKey.filterName = filterName;

        if (TextUtils.isEmpty(filterName)) {
            hideSeekBar();
            mtSDK.setBeautyFilterName(filterName, 0);
        } else {
            showNormalSeekBar();
            int progress = MtSharedPreferences.getInstance().getBeautyFilterValue(filterName);
            seekBar.setProgress(progress);
            styleNormal(progress);
            mtSDK.setBeautyFilterName(filterName, progress);
        }
    }

    @SuppressWarnings("unused")
    @Subscribe(thread = EventThread.MAIN_THREAD, tags = @Tag(RxBusAction.ACTION_FILTER_SELECTION))
    public void busCurrentFilterSelection(String filterName) {
        currentAction = RxBusAction.ACTION_FILTER;
        this.filterName = filterName;
        MtSharedPrefKey.filterName = filterName;

        if (TextUtils.isEmpty(filterName)) {
           hideSeekBar();
            mtSDK.setBeautyFilterName(filterName, 0);
        } else {
            showNormalSeekBar();
            int progress = MtSharedPreferences.getInstance().getBeautyFilterValue(filterName);
            seekBar.setProgress(progress);
            styleNormal(progress);
        }
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = { @Tag(RxBusAction.ACTION_EFFECT_FILTER) })
    public void busCurrentEffectFilter(MtEffectFilterEnum effectFilterEnum) {
        currentAction = RxBusAction.ACTION_EFFECT_FILTER;
        this.effectFilterEnum = effectFilterEnum;
        MtSharedPrefKey.effectFilterEnum = effectFilterEnum;

        if (this.effectFilterEnum == MtEffectFilterEnum.NO_FILTER) {
            hideSeekBar();
            mtSDK.setEffectFilterType(effectFilterEnum.getEffectFilter(), 0);
        } else {
            showNormalSeekBar();
            int progress = MtSharedPreferences.getInstance().getEffectFilterValue(effectFilterEnum.getFilterName(getContext()));
            seekBar.setProgress(progress);
            styleNormal(progress);
            mtSDK.setEffectFilterType(effectFilterEnum.getEffectFilter(), progress);
        }
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = {@Tag(RxBusAction.ACTION_TONE_FILTER)})
    public void busCurrentToneFilter(MtToneFilterEnum toneFilterEnum) {
        currentAction = RxBusAction.ACTION_TONE_FILTER;
        this.toneFilterEnum = toneFilterEnum;
        MtSharedPrefKey.toneFilterEnum = toneFilterEnum;

        if (this.toneFilterEnum == MtToneFilterEnum.NO_FILTER) {
            hideSeekBar();
            mtSDK.setToneFilterType(toneFilterEnum.getToneFilter(), 0);
        } else {
            showNormalSeekBar();
            int progress = MtSharedPreferences.getInstance().getToneFilterValue(toneFilterEnum.getFilterName(getContext()));
            seekBar.setProgress(progress);
            styleNormal(progress);
            mtSDK.setToneFilterType(toneFilterEnum.getToneFilter(), progress);
        }
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = @Tag(RxBusAction.ACTION_QUICK_BEAUTY))
    public void busCurrentQuickBeauty(MtQuickBeautyDefault quickBeautyDefault) {
        currentAction = RxBusAction.ACTION_QUICK_BEAUTY;
        this.quickBeautyDefault = quickBeautyDefault;
        MtSharedPrefKey.quickBeautyDefault = quickBeautyDefault;
        int progress = MtSharedPreferences.getInstance().getQuickBeautyValue(quickBeautyDefault.name());
        seekBar.setProgress(progress);
        styleNormal(progress);
        mtSDK.setBeautyStyle(quickBeautyDefault.beautyStyle, progress);
        setQuickBeauty(quickBeautyDefault, progress);
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = @Tag(RxBusAction.ACTION_QUICK_BEAUTY_SELECTION))
    public void busCurrentQuickBeautySelection(MtQuickBeautyDefault quickBeautyDefault) {
        this.quickBeautyDefault = quickBeautyDefault;
        MtSharedPrefKey.quickBeautyDefault = quickBeautyDefault;
        int progress = MtSharedPreferences.getInstance().getQuickBeautyValue(quickBeautyDefault.name());
        seekBar.setProgress(progress);
        styleNormal(progress);
        selectQuickBeauty();
    }

    @Subscribe(thread = EventThread.MAIN_THREAD)
    public void busCurrentAction(String currentAction) {
        this.currentAction = currentAction;
        switch (currentAction) {

            //美颜
            case RxBusAction.ACTION_WHITENESS:
                seekBar.setProgress(MtSharedPreferences.getInstance().getWhitenessValue());
                styleNormal(MtSharedPreferences.getInstance().getWhitenessValue());
                currentBeautyAction = RxBusAction.ACTION_WHITENESS;
                break;

            case RxBusAction.ACTION_BLURRINESS:
                seekBar.setProgress(MtSharedPreferences.getInstance().getBlurrinessValue());
                styleNormal(MtSharedPreferences.getInstance().getBlurrinessValue());
                currentBeautyAction = RxBusAction.ACTION_BLURRINESS;
                break;

            case RxBusAction.ACTION_PRECISE_SKIN:
                seekBar.setProgress(MtSharedPreferences.getInstance().getPreciseSkin());
                styleNormal(MtSharedPreferences.getInstance().getPreciseSkin());
                currentBeautyAction = RxBusAction.ACTION_PRECISE_SKIN;
                break;

            case RxBusAction.ACTION_ROSINESS:
                seekBar.setProgress(MtSharedPreferences.getInstance().getRosinessValue());
                styleNormal(MtSharedPreferences.getInstance().getRosinessValue());
                currentBeautyAction = RxBusAction.ACTION_ROSINESS;
                break;

            case RxBusAction.ACTION_CLEARNESS:
                seekBar.setProgress(MtSharedPreferences.getInstance().getClearnessValue());
                styleNormal(MtSharedPreferences.getInstance().getClearnessValue());
                currentBeautyAction = RxBusAction.ACTION_CLEARNESS;
                break;

            case RxBusAction.ACTION_BRIGHTNESS:
                seekBar.setProgress(MtSharedPreferences.getInstance().getBrightnessValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getBrightnessValue() + 50);
                currentBeautyAction = RxBusAction.ACTION_BRIGHTNESS;
                break;

            //美型
            case RxBusAction.ACTION_EYE_ENLARGING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getEyeEnlargingValue());
                styleNormal(MtSharedPreferences.getInstance().getEyeEnlargingValue());
                currentFaceTrimAction = RxBusAction.ACTION_EYE_ENLARGING;
                break;

            case RxBusAction.ACTION_CHEEK_THINNING://瘦脸
                seekBar.setProgress(MtSharedPreferences.getInstance().getCheekThinningValue());
                styleNormal(MtSharedPreferences.getInstance().getCheekThinningValue());
                currentFaceTrimAction = RxBusAction.ACTION_CHEEK_THINNING;
                break;

            case RxBusAction.ACTION_CHEEK_NARROWING://窄脸
                seekBar.setProgress(MtSharedPreferences.getInstance().getCheekNarrowingValue());
                styleNormal(MtSharedPreferences.getInstance().getCheekNarrowingValue());
                currentFaceTrimAction = RxBusAction.ACTION_CHEEK_NARROWING;
                break;

            case RxBusAction.ACTION_CHEEK_BONE_THINNING://瘦颧骨
                seekBar.setProgress(MtSharedPreferences.getInstance().getCheekboneThinningValue());
                styleNormal(MtSharedPreferences.getInstance().getCheekboneThinningValue());
                currentFaceTrimAction = RxBusAction.ACTION_CHEEK_BONE_THINNING;
                break;

            case RxBusAction.ACTION_JAW_BONE_THINNING://瘦下颌骨
                seekBar.setProgress(MtSharedPreferences.getInstance().getJawboneThinningValue());
                styleNormal(MtSharedPreferences.getInstance().getJawboneThinningValue());
                currentFaceTrimAction = RxBusAction.ACTION_JAW_BONE_THINNING;
                break;

            case RxBusAction.ACTION_TEMPLE_ENLARGING://丰太阳穴
                seekBar.setProgress(MtSharedPreferences.getInstance().getTempleEnlargingValue());
                styleNormal(MtSharedPreferences.getInstance().getTempleEnlargingValue());
                currentFaceTrimAction = RxBusAction.ACTION_TEMPLE_ENLARGING;
                break;

            case RxBusAction.ACTION_HEAD_LESSENING://小头
                seekBar.setProgress(MtSharedPreferences.getInstance().getHeadLesseningValue());
                styleNormal(MtSharedPreferences.getInstance().getHeadLesseningValue());
                currentFaceTrimAction = RxBusAction.ACTION_HEAD_LESSENING;
                break;

            case RxBusAction.ACTION_FACE_LESSENING://小脸
                seekBar.setProgress(MtSharedPreferences.getInstance().getFaceLesseningValue());
                styleNormal(MtSharedPreferences.getInstance().getFaceLesseningValue());
                currentFaceTrimAction = RxBusAction.ACTION_FACE_LESSENING;
                break;

            case RxBusAction.ACTION_CHIN_TRIMMING://下巴
                seekBar.setProgress(MtSharedPreferences.getInstance().getChinTrimmingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getChinTrimmingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_CHIN_TRIMMING;
                break;

            case RxBusAction.ACTION_PHILTRUM_TRIMMING://缩人中
                seekBar.setProgress(-(MtSharedPreferences.getInstance().getPhiltrumTrimmingValue() - 50));
                styleTransform(-(MtSharedPreferences.getInstance().getPhiltrumTrimmingValue() - 50));
                currentFaceTrimAction = RxBusAction.ACTION_PHILTRUM_TRIMMING;
                break;

            case RxBusAction.ACTION_FOREHEAD_TRIMMING://发际线
                seekBar.setProgress(MtSharedPreferences.getInstance().getForeheadTrimmingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getForeheadTrimmingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_FOREHEAD_TRIMMING;
                break;

            case RxBusAction.ACTION_EYE_SPACING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getEyeSpacingTrimmingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getEyeSpacingTrimmingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_EYE_SPACING;
                break;

            case RxBusAction.ACTION_EYE_CORNER_TRIMMING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getEyeCornerTrimmingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getEyeCornerTrimmingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_EYE_CORNER_TRIMMING;
                break;

            case RxBusAction.ACTION_EYE_CORNER_ENLARGING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getEyeCornerEnlargingValue());
                styleNormal(MtSharedPreferences.getInstance().getEyeCornerEnlargingValue());
                currentFaceTrimAction = RxBusAction.ACTION_EYE_CORNER_ENLARGING;
                break;

            case RxBusAction.ACTION_NOSE_ENLARGING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getNoseEnlargingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getNoseEnlargingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_NOSE_ENLARGING;
                break;

            case RxBusAction.ACTION_NOSE_THINNING:
                seekBar.setProgress(-(MtSharedPreferences.getInstance().getNoseThinningValue() - 50));
                styleTransform(-(MtSharedPreferences.getInstance().getNoseThinningValue() - 50));
                currentFaceTrimAction = RxBusAction.ACTION_NOSE_THINNING;
                break;

            case RxBusAction.ACTION_NOSE_APEX_LESSENING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getNoseApexLesseningValue());
                styleNormal(MtSharedPreferences.getInstance().getNoseApexLesseningValue());
                currentFaceTrimAction = RxBusAction.ACTION_NOSE_APEX_LESSENING;
                break;

            case RxBusAction.ACTION_NOSE_ROOT_ENLARGING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getNoseRootEnlargingValue());
                styleNormal(MtSharedPreferences.getInstance().getNoseRootEnlargingValue());
                currentFaceTrimAction = RxBusAction.ACTION_NOSE_ROOT_ENLARGING;
                break;

            case RxBusAction.ACTION_MOUTH_TRIMMING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getMouthTrimmingValue() + 50);
                styleTransform(MtSharedPreferences.getInstance().getMouthTrimmingValue() + 50);
                currentFaceTrimAction = RxBusAction.ACTION_MOUTH_TRIMMING;
                break;

            case RxBusAction.ACTION_MOUTH_SMILING:
                seekBar.setProgress(MtSharedPreferences.getInstance().getMouthSmilingEnlargingValue());
                styleNormal(MtSharedPreferences.getInstance().getMouthSmilingEnlargingValue());
                currentFaceTrimAction = RxBusAction.ACTION_MOUTH_SMILING;
                break;
            case RxBusAction.ACTION_DARK_CIRCLES:
                seekBar.setProgress(MtSharedPreferences.getInstance().getDarkCircleValue());
                styleNormal(MtSharedPreferences.getInstance().getDarkCircleValue());
                currentFaceTrimAction = RxBusAction.ACTION_DARK_CIRCLES;

        }
    }

    private void setQuickBeauty(MtQuickBeautyDefault quickBeauty, int progress) {
        float ratio = progress / 100f;

        this.filterName = quickBeauty.filterName;
        MtSharedPrefKey.filterName = quickBeauty.filterName;
        MtSharedPrefKey.selectedPositionFilter = quickBeauty.filterPosition;
        MtSharedPreferences.getInstance().setFilterSelectPosition(quickBeauty.filterPosition);
        MtSharedPreferences.getInstance().saveQuickBeautyChanged(quickBeauty, ratio);

        //改变重置按钮状态
        if (quickBeauty == MtQuickBeautyDefault.STANDARD_DEFAULT && progress == 100) {
            RxBus.get().post(RxBusAction.ACTION_RESET_IS_ENABLED, false);
        } else {
            postEnableReset();
        }
    }


    private void postEnableReset() {
        RxBus.get().post(RxBusAction.ACTION_RESET_IS_ENABLED, true);
    }

    @Subscribe(thread = EventThread.MAIN_THREAD, tags = {@Tag(value = "MT_BAR_TO_BLACK")})
    public void changeColor(Boolean toBlack) {
        if (toBlack) {
            numberTV.setTextColor(getResources().getColor(R.color.mt_text));
            renderEnableIV.setImageResource(R.drawable.icon_render_black);
        } else {
            numberTV.setTextColor(Color.WHITE);
            renderEnableIV.setImageResource(R.drawable.icon_render);
        }
    }
}
